package com.llp.javaweb.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author llp
 * {@code @date} 2022年11月06日22:35
 */
@WebServlet("/loginOut")
public class LoginOutServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //移除session域中的
        HttpSession session = req.getSession();
        Object user = session.getAttribute("user");
        if(user!=null)  session.removeAttribute("user");
        //重定向到首页
        resp.sendRedirect("/");


    }
}
